package cn.itcast.nems.config.mybatisplus;

import cn.itcast.nems.common.mybatisplus.TenantInterceptor;
import com.baomidou.mybatisplus.annotation.DbType;
import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
import lombok.Setter;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.List;

/**
 * author: yong.li
 * create: 2023-08-17 14:18:13
 **/
@Configuration
@ConfigurationProperties(prefix = "mybatis-plus")
@Setter
public class MybatisPlusConfig {
    private List<String> ignoreTenantTables;

    @Bean
    public MybatisPlusInterceptor mybatisPlusInterceptor() {
        MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
        interceptor.addInnerInterceptor(new PaginationInnerInterceptor(DbType.MYSQL));
        TenantInterceptor tenantInterceptor = new TenantInterceptor(ignoreTenantTables, "tenant_id");
        interceptor.addInnerInterceptor(tenantInterceptor);
        return interceptor;
    }

    @Bean
    public InsertBatchSqlInjector sqlInjector() {
        return new InsertBatchSqlInjector();
    }

}
